<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        
    </style>
</head>
<body>
    
</body>
<script>

    // 对象的结构的赋值
    const obj = {
        name:"admin",
        age:18,
        sex:"男",
        hobby:["篮球","足球"]
    }

    const { sex, age, name, hobby=[] } = obj;

    console.log(name);
    console.log(age);
    console.log(sex);

    console.log(hobby);



    // 删除数组指定位置的数据，删几个，替换一个新数据

    // splice({
    //     origin: arr,
    //     start: 3,
    //     num: 2,
    //     data: 2
    // })

    // function splice(obj){
        // var origin = obj.origin
        // var num = obj.num || 0;
        // var start = obj.start || 0;
        // var data = obj.data;
    //     var { origin,start=0,num=0,data } = obj;
    // }



    // 数组的结构的赋值
    const arr = [3,4];
    const [ qwe, asd, abc="hello" ] = arr;
    console.log(qwe);
    console.log(asd);
    console.log(abc);
    

    // 字符的解构赋值
    const str = "ly";
    const [ a, b, c="hello" ] = str;
    console.log(a);
    console.log(b);
    console.log(c);

        

    // 测试
    function fn({name, age}){
        console.log(name)
        console.log(age)
    }
    fn({name:"root",age:20})

    function fun(){
        return {
            year:2022,
            month:12,
            date:2
        }
    }
    const {year} = fun();
    console.log(year)

    
    let num1 = 10;
    let num2 = 20;
    [num2, num1] = [num1, num2];
    console.log(num1)
    console.log(num2)

</script>
</html>